package cn.yuhh.api;

import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.domain.AreaInfo;
import cn.yuhh.core.domain.Building;
import cn.yuhh.core.domain.DeclareInfo;
import cn.yuhh.core.domain.User;
import cn.yuhh.core.type.Role;
import cn.yuhh.core.util.DigestUtils;
import com.alibaba.fastjson.JSON;
import com.magic.spring.mongo.Mongo;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;

import java.util.Map;

/**
 * @author ysw
 * @create 2020-02-17 16:28
 * @descreption
 **/
@SpringBootApplication
@EntityScan("cn.yuhh.core.domain")
public class ApiApplication implements CommandLineRunner {

    public static void main(String[] args) {
        System.setProperty("tomcat.util.http.parser.HttpParser.requestTargetAllow", "{}");
        SpringApplication.run(ApiApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
          //1分工2审批 4签发
          //5是分工 和签发
          //3是分工审批
          //7是三个都有
//        AreaInfo areaInfo = new AreaInfo("市辖区","510801000000");
//        AreaInfo areaInfo1 = new AreaInfo("利州区","510802000000");
//        AreaInfo areaInfo3 = new AreaInfo("昭化区","510811000000");
//        AreaInfo areaInfo4 = new AreaInfo("朝天区","510812000000");
//        AreaInfo areaInfo5 = new AreaInfo("旺苍县","510821000000");
//        AreaInfo areaInfo6 = new AreaInfo("青川县","510822000000");
//        AreaInfo areaInfo7 = new AreaInfo("剑阁县","510823000000");
//        AreaInfo areaInfo2 = new AreaInfo("苍溪县","510824000000");
//        AreaInfo areaInfo8 = new AreaInfo("经济开发区","510825000000");
//
//        Mongo.buildMongo().insert(areaInfo);
//        Mongo.buildMongo().insert(areaInfo1);
//        Mongo.buildMongo().insert(areaInfo3);
//        Mongo.buildMongo().insert(areaInfo4);
//        Mongo.buildMongo().insert(areaInfo5);
//        Mongo.buildMongo().insert(areaInfo6);
//        Mongo.buildMongo().insert(areaInfo7);
//        Mongo.buildMongo().insert(areaInfo2);
//        Mongo.buildMongo().insert(areaInfo8);

//        AreaInfo areaInfo = Mongo.buildMongo().eq("countyCode", "510801000000").findOne(AreaInfo.class);
//        AreaInfo areaInfo1 = Mongo.buildMongo().eq("countyCode", "510802000000").findOne(AreaInfo.class);
//        User receiver = new User("受理人", "18113166332", DigestUtils.MD5("111111"), "djy", Role.RECEIVER, areaInfo);
//        User distHeader = new User("分工领导", "18113166333", DigestUtils.MD5("111111"), "djy", Role.DIST_HEADER, areaInfo);
//        User hander1 = new User("办理人员1", "18113166334", DigestUtils.MD5("111111"), "djy", Role.HANDLER, areaInfo);
//        User hander2 = new User("办理人员2", "18113166335", DigestUtils.MD5("111111"), "djy", Role.HANDLER, areaInfo);
//        User examer = new User("审批领导", "18113166336", DigestUtils.MD5("111111"), "djy", Role.EXAMINE_HEADER, areaInfo);
//        User issue = new User("签发领导", "18113166337", DigestUtils.MD5("111111"), "djy", Role.ISSUE_HEADER, areaInfo);
//
//        Mongo.buildMongo().insert(receiver);
//        Mongo.buildMongo().insert(distHeader);
//        Mongo.buildMongo().insert(hander1);
//        Mongo.buildMongo().insert(hander2);
//        Mongo.buildMongo().insert(examer);
//        Mongo.buildMongo().insert(issue);


        String srt = "{\n" +
                "  \"placeName\": \"我的地盘\",\n" +
                "  \"addr\": \"东街2号\",\n" +
                "  \"area\": \"123\",\n" +
                "  \"areaInfo\": {\n" +
                "    \"countyCode\": \"510802000000\",\n" +
                "    \"county\": \"利州区\"\n" +
                "  },\n" +
                "  \"buildingId\": \"\",\n" +
                "  \"height\": \"12\",\n" +
                "  \"storey\": \"12\",\n" +
                "  \"management\": \"为你好\",\n" +
                "  \"usageType\": \"办公\",\n" +
                "  \"contacts\": \"是我\",\n" +
                "  \"contactsTel\": \"1345678901\",\n" +
                "  \"userId\": \"\",\n" +
                "  \"userName\":\"姓名\",\n" +
                "  \"placeDesc\": \"场所\",\n" +
                "  \"businessLicense\": \"[]\",\n" +
                "  \"plan\": \"[]\",\n" +
                "  \"photos\": \"[]\",\n" +
                "  \"header\": \"方法\",\n" +
                "  \"headerTel\": \"123\"\n" +
                "}";
        Building building = AbstractApiService.map2bean(Building.class, JSON.parseObject(srt, Map.class));
        System.out.println(building);


    }
}